package com.letchat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letchat.pojo.Email;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface RegisterMapper extends BaseMapper<Email> {

    @Select("select * from email where email = #{email}")
    Email getByEmail(String email);

    @Insert("insert into email(email, captcha, update_time) " +
            "values (#{email},#{captcha},#{updateTime})")
    void save(Email email);

    @Update("update email set captcha = #{captcha}, update_time = #{updateTime} where email = #{email}")
    void updateCaptchaAndTime(String email, String captcha, LocalDateTime updateTime);

    @Select("select * from email where email = #{email} and captcha = #{captcha}")
    Email getByEmailAndCaptcha(String email, String captcha);

    @Update("update email set user_id = #{userId} where email = #{email}")
    void setUserIdByEmail(Integer userId, String email);
}
